package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.LabelInfo;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.admin.service.LabelInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by 小可乐$ on 2024/8/12$ 18:11$
 * description: 标签管理
 */
@Tag(name = "标签管理")
@RequestMapping("/admin/label")
@RestController
public class LabelController {
    @Autowired
    private LabelInfoService service;

    /**
     * 新增或修改标签信息
     * */
    @PostMapping("/saveOrUpdate")
    @Operation(summary = "新增或修改标签信息")
    public Result getAllLabel(@RequestBody LabelInfo labelInfo) {
        service.saveOrUpdate(labelInfo);
        return Result.ok();
    }
    /**
     * [根据类型查询标签列表]
     * */
    @GetMapping("list")
    @Operation(summary = "根据类型查询标签列表")
    public Result<List<LabelInfo>> getAllLabel(//可以不传
            @RequestParam(required = false) ItemType itemType) {
        LambdaQueryWrapper<LabelInfo> labelInfoLambdaQuery = new LambdaQueryWrapper<>();
        labelInfoLambdaQuery.eq(itemType!= null,LabelInfo::getType,itemType);
        List<LabelInfo> list = service.list(labelInfoLambdaQuery);
        return Result.ok(list);
    }
    /**
     * 根据id删除标签信息
     * */
    @DeleteMapping("deleteById")
    @Operation(summary = "根据id删除标签信息")
    public Result deleteById(@RequestParam  Long id){
        service.removeById(id);
        return Result.ok();
    }
}
